

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<script type="text/javascript" src="helpman_topicinit.js"></script>

<title>Tricks and Traps [Enterprise Architect User Guide]</title>

<meta name="keywords" content="Enterprise Architect, Sparx Systems, UML, Add-In Model,Add-In Model Create Add-In, Tricks and Traps,Tricks and Traps,Tricks and Traps Create Add-In,Re-entrancy,Re-entrancy In Add-Ins,Concurrent Method Calls,Concurrent Method Calls In Add-Ins,Add-In,Add-In And Enterprise ArchitectDeadlocks (.NET),Add-In COM Interoperability,Add-In Pre-2004,Add-In Re-entrancy,Add-In Visual Basic Issues,Add-In Concurrent Method Calls,Add-In Holding State Information">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />

<link type="text/css" href="default.css" rel="stylesheet" />
<style type="text/css">
  A, A:Visited
  {
    color: #00F;
  }

  A:Active, A:Hover
  {
    color: #F00;
  }

  OL
  {
    margin: 5px 0 5px 48px;
  }

  UL
  {
    margin-bottom: 3px;
    margin-top: 0;
  }

  #nsr
  {
    background-color: #D4DFFF;
  }

  #nsr A
  {
    text-decoration: none;
  }

  #mainbody
  {
    padding: 8px;
  }

  .p_BodyText
  {
    padding: 5px 0;
  }
</style>



<style type="text/css" media="screen">
  BODY
  {
    background-color: #FFFFFF;
  }

  #nsr
  {
    padding: 6px 6px 0 6px;
    border-bottom: none;
    vertical-align: top;
    z-index: 2;
    visibility: visible;
    left: 0;
    top: 0;
    position: absolute;
  }

  #mainbody
  {
    left: 0;
    top: 0;
    margin: 0;
    position: absolute;
    padding: 10px;
    overflow: auto;
    height: 100%;
    z-index: 1;
    background-repeat: no-repeat;
    background-position: bottom right;
    background-attachment: fixed;
  }
</style>

<style type="text/css" media="print">
  #nsr
  {
    visibility: none;
  }

  #mainbody
  {
    overflow: visible;
  }
</style>
<script type="text/javascript" language="JavaScript" src="nonscroll.js"></script>

</head>
<body scroll="no">

<div id="page">



        <div id="content">
          <div id="content-inner">
          



  
          <div id="nsr">
            <table border="0" cellspacing="0" cellpadding="4" width="100%">
              <tr valign="top">
                <td align="left">
  


                  <p class="p_Heading1"><span class="f_Heading1">Tricks and Traps</span></p>



  
                </td>
                <td align="right">
                  <a href="introduction.htm" onmouseover="document.images.main.src='button_main_h.gif'" onmouseout="document.images.main.src='button_main.gif'">
                    <img name="main" src="button_main.gif" border=0 alt="Return to Introduction">
                  </a>&nbsp;
    
                  <a href="deployingaddins.htm" onmouseover="document.images.prev.src='button_prev_h.gif'" onmouseout="document.images.prev.src='button_prev.gif'">
                    <img name=prev src="button_prev.gif" border=0 alt="Previous page" />
                  </a>&nbsp;
    
    
    
                  <a href="addinmanager.htm" onmouseover="document.images.next.src='button_next_h.gif'" onmouseout="document.images.next.src='button_next.gif'">
                    <img name=next src="button_next.gif" border=0 alt="Next page" />
                  </a>
    
    
                </td>
              </tr>
            </table>
          </div>
          <div id="mainbody">
  


                <p class="p_SubHeadingL1"><span class="f_SubHeadingL1">Visual Basic 5/6 Users Note</span></p>
<p class="p_BodyText"><span class="f_BodyText">Visual Basic 5/6 users should note that the version number of the Enterprise Architect interface is stored in the VBP project file in a form similar to the following:</span></p>
<p class="p_Code"><span class="f_Code">Reference=*\G{64FB2BF4-9EFA-11D2-8307-C45586000000}#2.2#0#..\..\..\..\Program Files\Sparx Systems\EA\EA.TLB#Enterprise Architect Object Model 2.02</span></p>
<p class="p_BodyText"><span class="f_BodyText">If you experience problems moving from one version of Enterprise Architect to another, open the VBP file in a text editor and remove this line. Then open the project in Visual Basic and use </span><span class="f_BodyText" style="font-style: italic;">Project-References</span><span class="f_BodyText"> to create a new reference to the Enterprise Architect Object model.</span></p>
<p class="p_SubHeadingL1"><span class="f_SubHeadingL1">Add-In Fails to Load</span></p>
<p class="p_BodyText"><span class="f_BodyText">From Enterprise Architect release 7.0, Add-Ins created before 2004 are no longer supported. If an Add-In subscribes to the </span><span class="f_Code">Addn_Tmpl.tlb</span><span class="f_BodyText"> interface (2003 style), it will fail on load. In this event, contact the vendor or author of the Add-In and request an upgrade.</span></p>
<p class="p_SubHeadingL1"><span class="f_SubHeadingL1">Holding State Information<a name="holding"></a></span></p>
<p class="p_BodyText"><span class="f_BodyText">It is possible for an Add-In to hold state information, meaning that data can be stored in member variables in response to one event and retrieved in another. There are some dangers in doing this:</span></p>
<ul style="text-indent: 0px; margin-left: 30px; list-style-position: outside;">
<li><span class="f_Bulletlist1">Enterprise Architect Automation Objects do not update themselves in response to user activity, to activity on other workstations, or even to the actions of other objects in the same automation client. Retaining handles to such objects between calls can result in the second event querying objects that have no relationship with the current state of Enterprise Architect.</span></li>
<li><span class="f_Bulletlist1">When you close Enterprise Architect, all Add-Ins are asked to shut down. If there are any external automation clients Enterprise Architect must stay active, in which case all the Add-Ins are reloaded, losing all the data.</span></li>
<li><span class="f_Bulletlist1">Enterprise Architect acting as an automation client does not close if an Add-In still holds a reference to it (releasing all references in the </span><span class="f_Code">Disconnect()</span><span class="f_Bulletlist1"> event avoids this problem).</span></li>
</ul>
<p class="p_BodyText"><span class="f_BodyText">It is recommended that unless there is a specific reason for doing so, the Add-In should use the repository parameter and its method and properties to provide the necessary data.</span></p>
<p class="p_SubHeadingL1"><span class="f_SubHeadingL1">Enterprise Architect Not Closing</span></p>
<p class="p_SubHeadingL2"><span class="f_SubHeadingL2">.Net Specific Issues</span></p>
<p class="p_BodyText"><span class="f_BodyText">Automation checks the use of objects and won't enable any of them to be destroyed until they are no longer being used.</span></p>
<p class="p_BodyText"><span class="f_BodyText">As noted in the </span><span class="f_BodyText" style="font-style: italic;"><a href="codesamples.htm">Automation Interface</a></span><span class="f_BodyText"> topic, if your automation controller was written using the .NET framework, Enterprise Architect does not close even after you release all your references to it. To force the release of the COM pointers, call the memory management functions as shown below:</span></p>
<p class="p_Code"><span class="f_Code">GC.Collect();</span></p>
<p class="p_Code"><span class="f_Code">GC.WaitForPendingFinalizers();</span></p>
<p class="p_BodyText"><span class="f_BodyText">Additionally, because automation clients hook into Enterprise Architect, which creates Add-Ins which in turn hook back into Enterprise Architect, it is possible to get into a deadlock situation where Enterprise Architect and the Add-Ins won't let go of one another and keep each other active. An Add-In might retain hooks into Enterprise Architect because:</span></p>
<ul style="text-indent: 0px; margin-left: 30px; list-style-position: outside;">
<li><span class="f_Bulletlist1">It keeps a private reference to an Enterprise Architect object (see <a href="tricksandtraps.htm#Holding">Holding State Information</a> above), or</span></li>
<li><span class="f_Bulletlist1">It has been created by .NET and the GC mechanism hasn't got around to releasing it.</span></li>
</ul>
<p class="p_BodyText"><span class="f_BodyText">There are two actions required to avoid deadlock situations:</span></p>
<ul style="text-indent: 0px; margin-left: 30px; list-style-position: outside;">
<li><span class="f_Bulletlist1">Automation controllers must call </span><span class="f_Code">Repository.CloseAddins()</span><span class="f_Bulletlist1"> at some point (presumably at the end of processing).</span></li>
<li><span class="f_Bulletlist1">Add-Ins must release all references to Enterprise Architect in the </span><span class="f_Code">Disconnect()</span><span class="f_Bulletlist1" style="font-style: italic;"> </span><span class="f_Bulletlist1">event. See the </span><span class="f_Bulletlist1" style="font-style: italic;"><a href="eaaddintemplateobject.htm">Add-In Methods</a></span><span class="f_Bulletlist1"> topic for details.</span></li>
</ul>
<p class="p_BodyText"><span class="f_BodyText">It is possible that your Automation client controls a running instance of Enterprise Architect where the Add-Ins have not complied with the rule above. In this case you could call </span><span class="f_Code">Repository.Exit()</span><span class="f_BodyText"> to terminate Enterprise Architect.</span></p>
<p class="p_SubHeadingL2"><span class="f_SubHeadingL2">Miscellaneous</span></p>
<p class="p_BodyText"><span class="f_BodyText">In developing Add-Ins using the .Net framework you must select COM Interoperability in the project's properties in order for it to be recognized as an Add-In.</span></p>
<p class="p_BodyText"><span class="f_BodyText">Some development environments do not automatically register COM DLLs on creation. You might have to do that manually before Enterprise Architect recognizes the Add-In.</span></p>
<p class="p_BodyText"><span class="f_BodyText">You can use your private Add-In key (as required for Add-In deployment) to store configuration information pertinent to your Add-In.</span></p>
<p class="p_SubHeadingL1"><span class="f_SubHeadingL1">Concurrent calls</span></p>
<p class="p_BodyText"><span class="f_BodyText">In Enterprise Architect releases up to release 7.0, there is a possibility that Enterprise Architect could call two Add-In methods concurrently if the Add-In calls:</span></p>
<ul style="text-indent: 0px; margin-left: 30px; list-style-position: outside;">
<li><span class="f_Bulletlist1">A message box</span></li>
<li><span class="f_Bulletlist1">A modal dialog</span></li>
<li><span class="f_Bulletlist1">VB DoEvents, .NET Application DoEvents or the equivalent in other languages</span>.</li>
</ul>
<p class="p_BodyText"><span class="f_BodyText">In such cases, Enterprise Architect could initiate a second Add-In method before the first returns (re-entrancy). In release 7.0. and subsequent releases, Enterprise Architect cannot make such concurrent calls.</span></p>
<p class="p_BodyText"><span class="f_BodyText">If developing Add-Ins, ensure that the Add-In users are running Enterprise Architect release 7.0 or a later release to avoid any risk of concurrent method calls.</span></p>




            </div>
          </div>
        </div>



</div>


</body>
</html>
